Repository navigation
Conversation
…il body A mail body renders in a sandboxed iframe (the standard reader and every chat-view bubble), which is a document of its own. Clicking in it, a link above all, made that frame the focused frame, and Chromium then delivered every keydown to the frame's document. The shortcut listeners are on the app's document, so j/k, e, #, / and Escape went dead until the user clicked outside the body. Returning from the browser a link opened in did not help: the window-focus restore leaves an already-focused element alone, and the frame is that element. Keydowns in a frame that runs no script (sandboxed without allow-scripts, i.e. the mail bodies) are now replayed on the iframe element in the app's document, attached when focus enters the frame (window blur with the frame active) and re-attached when the frame loads a new document. If an app listener handles the replay, the original is prevented too. Focus stays in the frame, so copying a selection there keeps working; keys typed into a field in the mail and IME composition are not forwarded; extension panels (which run script) are left alone. No sandbox or CSP change. The shortcut hook now uses the shared, realm-agnostic typing-target check, and its go-to console.log lines move to the shared logger without the key.
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After a click on a link in an email (or anywhere in its text), every keyboard shortcut stopped working: j/k, e, #, /, Escape. They stayed dead until the user clicked somewhere outside the message body.
Root cause
A mail body is rendered in a sandboxed
<iframe>, which is a separate document. That is true ofSandboxedEmailBodyand of each chat-view bubble in@sarv-in/email-chat-view. A click inside it makes that frame the focused frame, so Chromium sends every later keydown to the frame's document. The shortcut listeners are on the app's document.Coming back from the browser that the link opened in did not help. The window-focus restore in
App.tsxleaves an element that already has focus alone, and the iframe is that element. Confirmed in real Chromium: after the click,document.activeElementis theIFRAME.Fix
New
apps/desktop/src/utils/frame-key-forwarding.ts, installed once inmain.tsx:useClickAwayuses), that frame's document starts forwarding keydowns.KeyboardEventon the<iframe>element in the app's document, so it reaches the same listeners a key pressed in the app would. If an app listener handles it (callspreventDefault), the original key is prevented too.sandboxset and noallow-scripts: the mail bodies. Extension panels run script and own their own keyboard, so they are left alone. The PDF viewer frame is unsandboxed and cross-origin, so it is not touched either.useKeyboardShortcutsreuses the sharedisTypingTarget, because an element inside a frame is not aninstanceofthe app'sHTMLElement.Also: the go-to-mode
console.loglines inuseKeyboardShortcutsnow use the shared logger at debug level, and no longer log the key.Tests
apps/desktop/test/unit/src/utils/frame-key-forwarding.test.tsxhas 15 tests using real srcdoc frames in happy-dom. Each test names the regression it guards. They cover:repeatcopied;preventDefaultpassed back only when an app listener handled the key;Processkeys not forwarded;useKeyboardShortcuts: after a link click,ddeletes andEscapecloses, whiledtyped into a field in the mail deletes nothing.Results:
preventDefaulthand-back or the reload re-attach each turns tests red.TURBO_FORCE=true pnpm test) green before the merge with main: core 4583, storage-node 1950, desktop 11873 (17 skipped, none new), site 144.This branch now includes a merge of main (1.5.0). The only conflict was in CHANGELOG.md: the entry sits under
[Unreleased], above 1.5.0.devalready has this fix (1eac413).🤖 Generated with Claude Code